let fs = require('fs')

let rs = fs.createReadStream('test.txt', {
  highWaterMark: 4
})

let ws = fs.createWriteStream('test1.txt', {
  highWaterMark: 1//缓存大小
})

let flag = true

//pipe 内部实现原理  
/* rs.on('data', (chunk) => {
  flag = ws.write(chunk, () => {
    console.log('写完了')
  })
  console.log(flag);
  //可写流 超限
  if (!flag) {
    //暂停可写流
    rs.pause()
  }
})
//缓存中有空间可以继续写入
ws.on('drain', () => {
  rs.resume()
}) */

rs.pipe(ws)